package net.jsoft.pms.repository.ywfwqd;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import net.jsoft.pms.entity.ywfwqd.YwfwqdEntity;

@Transactional
@Component
public interface YwfwqdRepository extends PagingAndSortingRepository<YwfwqdEntity, Long>, JpaSpecificationExecutor<YwfwqdEntity>
{

    @Query("from YwfwqdEntity where ywfwid = :ywfwid")
    YwfwqdEntity findOneByYwfwid(@Param("ywfwid") String ywfwid);
    
    @Modifying
    @Query("update YwfwqdEntity set dwfbzt= (case dwfbzt when '3' then '1'  when '4' then '1' when '5' then '2' else '1' end) where  id in ?1")
    void updateDwfwztPublished(List<Long> ids);

    @Modifying
    @Query("update YwfwqdEntity set dwfbzt= '5' where  id in ?1")
    void updateDwfwztCancel(List<Long> ids);

    @Modifying
    @Query("update YwfwqdEntity set dwfbzt= '4' where  id in ?1")
    void updateDwfwztUnCancel(List<Long> ids);

    @Query("from YwfwqdEntity where lrrq between  :start and :end or xgrq between  :start and :end  ")
    List<YwfwqdEntity> getPeriodYwfwqd(@Param("start") Date start, @Param("end") Date end);

    //    @Query("SELECT * FROM( SELECT substring_index(ywfwxh,'_',2) colname , max(substring_index(ywfwxh,'_',-1) ) as num FROM  t_dzswj_ywfwqdb  group by colname  ) T WHERE T.colname IN ('BS_MHQX','BS_SBJS','BS_XXFW','BS_ZXBS')")
    //    List<Map<String, Object>> queryYwfwxh();
}
